add_definitions(-DTRANSLATION_DOMAIN=\"kcmkeyboard\")

add_subdirectory(tastenbrett)

option(HAVE_XINPUT "X11 XInput" OFF)
option(HAVE_UDEV "UDev" OFF)

if (X11_Xinput_FOUND)
    set(HAVE_XINPUT ON)
elseif (UDEV_FOUND)
    set(HAVE_UDEV ON)
else()
    message(STATUS "X11 XInput and UDev is not found, either is required to keep layouts with keyboard hotplugging")
endif()

### kded daemon ###

set( kded_keyboard_SRCS
    keyboard_daemon.cpp
    layout_memory.cpp
    layout_memory_persister.cpp
    udev_helper.cpp
    x11_helper.cpp
    xinput_helper.cpp
    xkb_helper.cpp
    keyboard_config.cpp
    keyboard_hardware.cpp
    bindings.cpp
# next are temporary for sys tray UI
    layout_tray_icon.cpp
    layouts_menu.cpp
    flags.cpp
    xkb_rules.cpp
)

ecm_qt_declare_logging_category(kded_keyboard_SRCS
    HEADER debug.h
    IDENTIFIER KCM_KEYBOARD
    CATEGORY_NAME org.kde.kcm_keyboard
    DEFAULT_SEVERITY Warning)


include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_library(kded_keyboard MODULE ${kded_keyboard_SRCS})
set_target_properties(kded_keyboard PROPERTIES OUTPUT_NAME keyboard)
kcoreaddons_desktop_to_json(kded_keyboard keyboard.desktop SERVICE_TYPES kdedmodule.desktop)

target_link_libraries(kded_keyboard
    Qt5::Concurrent
    Qt5::Widgets
    Qt5::X11Extras
    Qt5::Xml
    KF5::ConfigCore
    KF5::CoreAddons
    KF5::DBusAddons
    KF5::GlobalAccel
    KF5::I18n
    KF5::Notifications
    KF5::WindowSystem
    KF5::Plasma
    KF5::XmlGui
    KF5::GuiAddons
    KF5::IconThemes
    XCB::XCB
    XCB::XKB
    ${X11_LIBRARIES}
    ${X11_Xkbfile_LIB}
 )

if (HAVE_XINPUT)
    target_link_libraries(kded_keyboard ${X11_Xinput_LIB})
endif()

if (HAVE_UDEV)
    target_link_libraries(kded_keyboard ${UDEV_LIBS})
endif()

install( TARGETS kded_keyboard DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/kded )

### kcm keyboard ###

set(kcm_keyboard_PART_SRCS
  kcm_keyboard.cpp
  kcm_keyboard_widget.cpp
  kcm_view_models.cpp
  kcm_add_layout_dialog.cpp
  keyboard_config.cpp
  x11_helper.cpp
  xkb_helper.cpp
  xkb_rules.cpp
  flags.cpp
  iso_codes.cpp
  kcmmisc.cpp
  bindings.cpp
  tastenbrett.cpp)

ecm_qt_declare_logging_category(kcm_keyboard_PART_SRCS
    HEADER debug.h
    IDENTIFIER KCM_KEYBOARD
    CATEGORY_NAME org.kde.kcm_keyboard
    DEFAULT_SEVERITY Warning)

ki18n_wrap_ui(kcm_keyboard_PART_SRCS kcm_keyboard.ui kcm_add_layout_dialog.ui kcmmiscwidget.ui)

add_library(kcm_keyboard MODULE ${kcm_keyboard_PART_SRCS})

target_link_libraries(kcm_keyboard
    Qt5::Concurrent
    Qt5::Widgets
    Qt5::X11Extras
    Qt5::Xml
    KF5::KCMUtils
    KF5::GlobalAccel
    KF5::I18n
    KF5::KIOCore
    KF5::KIOWidgets
    KF5::WindowSystem
    KF5::Plasma
    KF5::XmlGui
    KF5::GuiAddons
    KF5::IconThemes
    XCB::XCB
    XCB::XKB
    ${X11_Xkbfile_LIB}
    ${X11_LIBRARIES}
    ${text_paint_LIB}
)

install(TARGETS kcm_keyboard DESTINATION ${KDE_INSTALL_PLUGINDIR} )

install( FILES kcm_keyboard.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} )

# Images

add_subdirectory( pics )

configure_file(config-keyboard.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-keyboard.h)

# Unit tests
if(BUILD_TESTING)
    find_package(Qt5Test ${QT_MIN_VERSION} CONFIG REQUIRED)
    add_subdirectory( tests )
endif()

add_dependencies(kcm_keyboard tastenbrett)
